/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementNonstandardocsBo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementNonstandardocsVo;
import com.comac.ins.isfd.service.IIsfdModelManagementNonstandardocsService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * 模型组件-非标文件
 *
 * @author Lion Li
 * @date 2024-09-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/modelManagementNonstandardocs")
public class IsfdModelManagementNonstandardocsController extends BaseController {

    private final IIsfdModelManagementNonstandardocsService isfdModelManagementNonstandardocsService;

    /**
     * 查询模型组件-非标文件列表
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdModelManagementNonstandardocsVo> list(IsfdModelManagementNonstandardocsBo bo, PageQuery pageQuery) {
        return isfdModelManagementNonstandardocsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出模型组件-非标文件列表
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:export")
    @Log(title = "模型组件-非标文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdModelManagementNonstandardocsBo bo, HttpServletResponse response) {
        List<IsfdModelManagementNonstandardocsVo> list = isfdModelManagementNonstandardocsService.queryList(bo);
        ExcelUtil.exportExcel(list, "模型组件-非标文件", IsfdModelManagementNonstandardocsVo.class, response);
    }

    /**
     * 获取模型组件-非标文件详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:query")
    @GetMapping("/{id}")
    public R<IsfdModelManagementNonstandardocsVo> getInfo(@NotNull(message = "主键不能为空")
                                                          @PathVariable Long id) {
        return R.ok(isfdModelManagementNonstandardocsService.queryById(id));
    }

    /**
     * 新增模型组件-非标文件
     *//*
    @SaCheckPermission("isfd:modelManagementNonstandardocs:add")
    @Log(title = "模型组件-非标文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdModelManagementNonstandardocsBo bo) {
        return toAjax(isfdModelManagementNonstandardocsService.insertByBo(bo));
    }*/

    /**
     * 新增模型组件-非标文件
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:save")
    @Log(title = "新增模型组件-非标文件", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<IsfdModelManagementNonstandardocsVo> save(@RequestParam("file") MultipartFile file,
                                                       @RequestParam("remark") String remark) {
        return R.ok(isfdModelManagementNonstandardocsService.save(file, remark));
    }

    /**
     * 修改模型组件-非标文件
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:edit")
    @Log(title = "模型组件-非标文件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdModelManagementNonstandardocsBo bo) {
        return toAjax(isfdModelManagementNonstandardocsService.updateByBo(bo));
    }

    /**
     * 删除模型组件-非标文件
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:modelManagementNonstandardocs:remove")
    @Log(title = "模型组件-非标文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdModelManagementNonstandardocsService.deleteWithValidByIds(List.of(ids), true));
    }
}
